package com.qf.vo;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class BaseResult {


    private boolean success;

    private String message;

    private Integer code;

    private Map<String,Object> data = new HashMap<String,Object>();

    public BaseResult(boolean success, String message, Integer code, Map<String, Object> data) {
        this.success = success;
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public static BaseResult ok(){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(BaseResultEnum.SUCCESS.getSuccess());
        baseResult.setCode(BaseResultEnum.SUCCESS.getCode());
        baseResult.setMessage(BaseResultEnum.SUCCESS.getMessage());
        return baseResult;
    }

    public static BaseResult error(){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(BaseResultEnum.UNKNOWN_REASON.getSuccess());
        baseResult.setCode(BaseResultEnum.UNKNOWN_REASON.getCode());
        baseResult.setMessage(BaseResultEnum.UNKNOWN_REASON.getMessage());
        return baseResult;
    }

    public BaseResult() {
    }

    public BaseResult Success(boolean success) {
        this.success = success;
        return this;
    }

    public BaseResult Message(String message) {
        this.message = message;
        return this;
    }

    public BaseResult Code(Integer code) {
        this.code = code;
        return this;
    }

    public BaseResult Data(Map<String, Object> data) {
        this.data = data;
        return this;
    }

    public BaseResult Data(String ket,Object value) {
        this.data.put(ket, value);
        return this;
    }

}
